package cn.sowz.mvc.interceptor;

import cn.sowz.mvc.prop.ShowProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class ShowInfoInterceptor implements HandlerInterceptor {
    @Autowired
    private ShowProperties showProperties;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // return HandlerInterceptor.super.preHandle(request, response, handler);
        if (showProperties.isShow()){
            if (StringUtils.hasText(showProperties.getInfo())){
                log.info("info: {}",showProperties.getInfo());
            }else{
                log.info("default info: {}","hello 屌毛屌毛。。。");
            }
        }
        return true;
    }
}
